package com.songqintuan.mall.util;

import com.songqintuan.model.po.Ncounter;

public class NcounterUtil {
	public static final String ZERO_STRING = "0";

	public static String getNo(Ncounter ncounter) {
		String prefix = ncounter.getPrefix();
		long nextNumber = ncounter.getCounterNext();
		int counterLength = ncounter.getCounterLength();
		String counter = constructLastCounter(counterLength, nextNumber);
		return prefix + counter;
	}

	public static String constructLastCounter(int counterLength,
			long lastCounter) {
		String str = String.valueOf(lastCounter);
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < counterLength - str.length(); i++) {
			buffer.append(ZERO_STRING);
		}
		buffer.append(str);
		return buffer.toString();
	}

}
